//
//  JCAddBankView.m
//  JiFengDaRen
//
//  Created by shouhan on 2018/3/29.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "JCAddBankView.h"
#import "UIButton+ImageTitleSapce.h"

@interface JCAddBankView ()

@property (nonatomic, strong) UIView * promptView;

@property (nonatomic, strong) UILabel * promptLabel;

@property (nonatomic, strong) UIView * bankView;

@property (nonatomic, strong) UILabel * bankLabel;


@property (nonatomic, strong) UIView * phoneView;

@property (nonatomic, strong) UILabel * phoneLabel;


@property (nonatomic, strong) UIView * provinceView;

@property (nonatomic, strong) UILabel * provinceLabel;

@property (nonatomic, strong) UIButton * chooseProBtn;

@property (nonatomic, strong) UIView * cityView;

@property (nonatomic, strong) UILabel * cityLabel;

@property (nonatomic, strong) UIButton * chooseCityBtn;

@property (nonatomic, strong) UIView * bankNameView;

@property (nonatomic, strong) UILabel * bankName;

@property (nonatomic, strong) UIButton * chooseBankBtn;

@property (nonatomic, strong) UIButton * confirmBtn;// 确定的按钮

@end

@implementation JCAddBankView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI{
    
    self.backgroundColor = KBASEBGCOLOR;
    
    self.promptView = [UIView new];
    self.promptView.backgroundColor = KBASEBGCOLOR;
    [self addSubview:self.promptView];
    
    self.promptLabel = [UILabel new];
    self.promptLabel.text = @"*请绑定持卡人本人的信用卡";
    self.promptLabel.textColor = KSHTEXTCOLOR;
    self.promptLabel.font = KSystemFont(__I6Width(13));
    self.promptLabel.textAlignment = NSTextAlignmentLeft;
    [self.promptView addSubview:self.promptLabel];
    
    self.bankView = [UIView new];
    self.bankView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.bankView];
    
    self.bankLabel = [UILabel new];
    self.bankLabel.text = @"银行卡号";
    self.bankLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.bankLabel.font = KSystemFont(__I6Width(13));
    [self.bankView addSubview:self.bankLabel];
    
    self.bankField = [UITextField new];
    self.bankField.placeholder = @"请输入银行卡号";
    self.bankField.keyboardType = UIKeyboardTypeNumberPad;
    [self.bankField setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.bankField  setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
    self.bankField.font = KSystemFont(__I6Width(14));
    self.bankField.textColor = [UIColor blackColor];
    self.bankField.clearButtonMode  = UITextFieldViewModeAlways;
    [self.bankView addSubview:self.bankField];
    
    self.phoneView = [UIView new];
    self.phoneView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.phoneView];
    
    self.phoneLabel = [UILabel new];
    self.phoneLabel.text = @"手机号";
    self.phoneLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.phoneLabel.font = KSystemFont(__I6Width(13));
    [self.phoneView addSubview:self.phoneLabel];
    
    self.phoneField = [UITextField new];
    self.phoneField.placeholder = @"请输入预留手机号";
    self.phoneField.keyboardType = UIKeyboardTypeNumberPad;
    self.phoneField.font = KSystemFont(__I6Width(14));
    self.phoneField.textColor = [UIColor blackColor];
    [self.phoneField setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.phoneField setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
    self.phoneField.clearButtonMode = UITextFieldViewModeAlways;
    [self.phoneView addSubview:self.phoneField];
    
    self.provinceView = [UIView new];
    self.provinceView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.provinceView];
    
    self.provinceLabel = [UILabel new];
    self.provinceLabel.text = @"银行卡所属省份";
    self.provinceLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.provinceLabel.font = KSystemFont(__I6Width(13));
    [self.provinceView addSubview:self.provinceLabel];
    
    self.chooseProBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.chooseProBtn setTitle:@"请选择" forState:UIControlStateNormal];
    [self.chooseProBtn setImage:[UIImage imageNamed:@"jmarrow"] forState:UIControlStateNormal];
    [self.chooseProBtn setTitleColor:[UIColor colorWithHexString:@"#474958"] forState:UIControlStateNormal];
    self.chooseProBtn.titleLabel.font = KSystemFont(__I6Width(13));
    self.chooseProBtn.tag = 1001;
    [self.chooseProBtn addTarget:self action:@selector(BtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.chooseProBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:10];
    self.chooseProBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.provinceView addSubview:self.chooseProBtn];
    
    self.cityView = [UIView new];
    self.cityView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.cityView];
    
    self.cityLabel = [UILabel new];
    self.cityLabel.text = @"银行卡所属城市";
    self.cityLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.cityLabel.font = KSystemFont(__I6Width(13));
    [self.cityView addSubview:self.cityLabel];
    
    self.chooseCityBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.chooseCityBtn setTitle:@"请选择" forState:UIControlStateNormal];
    [self.chooseCityBtn setImage:[UIImage imageNamed:@"jmarrow"] forState:UIControlStateNormal];
    [self.chooseCityBtn setTitleColor:[UIColor colorWithHexString:@"#474958"] forState:UIControlStateNormal];
    self.chooseCityBtn.titleLabel.font = KSystemFont(__I6Width(13));
    self.chooseCityBtn.tag = 1002;
    [self.chooseCityBtn addTarget:self action:@selector(BtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.chooseCityBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:10];
    self.chooseCityBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.cityView addSubview:self.chooseCityBtn];
    
    self.bankNameView = [UIView new];
    self.bankNameView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.bankNameView];
    
    self.bankName = [UILabel new];
    self.bankName.text = @"银行名称";
    self.bankName.textColor = [UIColor colorWithHexString:@"#474958"];
    self.bankName.font = KSystemFont(__I6Width(13));
    [self.bankNameView addSubview:self.bankName];

    self.chooseBankBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.chooseBankBtn setTitle:@"请选择" forState:UIControlStateNormal];
    [self.chooseBankBtn setImage:[UIImage imageNamed:@"jmarrow"] forState:UIControlStateNormal];
    [self.chooseBankBtn setTitleColor:[UIColor colorWithHexString:@"#474958"] forState:UIControlStateNormal];
    self.chooseBankBtn.titleLabel.font = KSystemFont(__I6Width(13));
    self.chooseBankBtn.tag = 1003;
    [self.chooseBankBtn addTarget:self action:@selector(BtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.chooseBankBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:10];
    self.chooseBankBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.bankNameView addSubview:self.chooseBankBtn];
    
    self.confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.confirmBtn.backgroundColor = KREDCOLOR;
    self.confirmBtn.layer.cornerRadius = __I6Width(8);
    self.confirmBtn.layer.masksToBounds = YES;
    self.confirmBtn.titleLabel.font = KSystemFont(__I6Width(16));
    [self.confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [self.confirmBtn setBackgroundImage:[UIImage imageNamed:@"loginHilight"] forState:UIControlStateHighlighted];
    self.confirmBtn.tag = 1004;    
    [self.confirmBtn addTarget:self action:@selector(BtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.confirmBtn];
    
}
- (void)layoutSubviews{
    [super layoutSubviews];

    [self.promptView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_offset(__I6Height(30));
    }];
    
    [self.promptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.promptView).offset(__I6Width(15));
        make.right.equalTo(self.promptView).offset(-__I6Width(15));
        make.centerY.equalTo(self.promptView);
    }];
    
    [self.bankView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.promptView.mas_bottom).offset(0);
        make.height.mas_equalTo(__I6Height(42));
    }];
    
    [self.bankLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bankView).offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.bottom.top.equalTo(self.bankView);
    }];

    [self.bankField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.bankView);
        make.left.equalTo(self.bankLabel.mas_right).offset(__I6Width(20));
        make.right.equalTo(self.bankView).offset(-__I6Width(15));
    }];
    
    [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.bankView.mas_bottom).offset(1);
        make.height.equalTo(self.bankView.mas_height);
    }];
    
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.phoneView).offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.top.bottom.equalTo(self.phoneView);
    }];
    
    [self.phoneField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.phoneView);
        make.left.equalTo(self.phoneLabel.mas_right).offset(__I6Width(20));
        make.right.equalTo(self.phoneView).offset(__I6Width(-15));
    }];
    
    [self.provinceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.phoneView.mas_bottom).offset(1);
        make.height.equalTo(self.bankView.mas_height);
    }];
    
    [self.provinceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.provinceView);
        make.left.equalTo(self.provinceView).offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(120));
    }];
    
    [self.chooseProBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.provinceView);
        make.left.equalTo(self.provinceLabel.mas_right).offset(__I6Width(20));
        make.right.equalTo(self.provinceView).offset(-__I6Width(30));
    }];
    
    [self.cityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.provinceView.mas_bottom).offset(1);
        make.height.equalTo(self.bankView.mas_height);
    }];
    
    [self.cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.cityView);
        make.left.equalTo(self.cityView).offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(120));
    }];
    
    [self.chooseCityBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.cityView);
        make.left.equalTo(self.cityLabel.mas_right).offset(__I6Width(20));
        make.right.equalTo(self.cityView).offset(-__I6Width(30));
    }];
    
    [self.bankNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.cityView.mas_bottom).offset(1);
        make.height.equalTo(self.bankView.mas_height);
    }];
    
    [self.bankName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.bankNameView);
        make.left.equalTo(self.bankNameView).offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(120));
    }];
    
    [self.chooseBankBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.bankNameView);
        make.left.equalTo(self.bankName.mas_right).offset(__I6Width(20));
        make.right.equalTo(self.bankNameView).offset(-__I6Width(30));
    }];
    
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bankNameView.mas_bottom).offset(__I6Height(50));
        make.centerX.mas_equalTo(self.mas_centerX);
        make.width.mas_equalTo(__I6Width(326));
        make.height.mas_equalTo(__I6Height(42));
    }];
}

- (void)BtnAction:(UIButton *)btn{
    
    NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:@(btn.tag),@"tag", nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"addCard" object:nil userInfo:dic];

}

- (void)getPickerAreaProvince:(NSString *)province City:(NSString *)city{
    
    [self.chooseProBtn setTitle:province forState:UIControlStateNormal];
    
    [self.chooseCityBtn setTitle:city forState:UIControlStateNormal];
}

- (void)getBankName:(NSString *)bankName{
    [self.chooseBankBtn setTitle:bankName forState:UIControlStateNormal];
}


@end
